using System;
using System.Collections.Generic;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace MyFirstGame.Objects
{
    public enum Direction : short
    {
        Right,
        Left,
        Up,
        Down,
        DiagonalUpLeft,
        DiagonalUpRight,
        DiagonalDownLeft,
        DiagonalDownRight

    }

    public enum BulletStatus : short
    {
        Moving,
        Hit
    }

    class Bullet
    {
        private Vector2 _position;
        private Texture2D[] _textures;
        private Direction _direction;
        private float _speedFactor;
        private int _textureIndex;
        private int _damagePower;
        private BulletStatus _bulletStatus;

        public Bullet(Vector2 initPosition, Direction direction, float speedFactor, int damagePower, Texture2D[] textures)
        {
            this._textures = textures;
            this._position = initPosition;
            this._direction = direction;
            this._speedFactor = speedFactor;
            this._textureIndex = 0;
            this._damagePower = damagePower;
            this._bulletStatus = BulletStatus.Moving;

            this._position = new Vector2(initPosition.X - (this._textures[0].Width / 2) + 50, initPosition.Y - (this._textures[0].Height / 2));
        }

        public Texture2D[] Textures
        {
            get
            {
                return (this._textures);
            }
        }

        public Texture2D CurrentTexture
        {
            get
            {
                if (this._bulletStatus == BulletStatus.Hit)
                {
                    this.AnimBullet();
                }
                return (this._textures[this._textureIndex]);
            }
        }

        public int DamagePower
        {
            get
            {
                return (this._damagePower);
            }
        }

        public Vector2 Position
        {
            get
            {
                return (this._position);
            }
            set
            {
                this._position = value;
            }
        }

        public Direction Direction
        {
            get
            {
                return (this._direction);
            }
        }

        public BulletStatus Status
        {
            get
            {
                return (this._bulletStatus);
            }
        }

        public void UpdateBulletPosition()
        {
            switch (this._direction)
            {
                case Direction.Right:
                    this._position.X += this._speedFactor;
                    break;
            }
        }

        public void ChangeBulletStatus(BulletStatus newBulletStatus)
        {
            this._bulletStatus = newBulletStatus;
        }

        public void AnimBullet()
        {
            this._textureIndex++;

            if (this._textureIndex > this._textures.Length - 1)
            {
                this._textureIndex = this._textures.Length - 1;
            }
        }
    }
}
